package view;

import java.awt.BorderLayout;
import java.awt.Color;

import javax.swing.BorderFactory;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.border.TitledBorder;

import resources.ResourceProvider;

/**
 * folder hierarchy panel class
 *
 */
public class FolderHierarchyPanel extends JPanel
{

	/**
	 * 
	 */
	private static final long serialVersionUID = 6394731408263836450L;
	
	private EMailFolderHierarchyTree etree;
	
	private EmailApplicationView emailApplicationView;
	
	private EmailFolderNode mailbox;

	/**
	 * constructor
	 * @param emailApplicationView the application view reference
	 */
	public FolderHierarchyPanel(EmailApplicationView emailApplicationView) 
	{
		this.setLayout(new BorderLayout(10, 10));
	    this.setBackground(Color.lightGray);
	    TitledBorder title = BorderFactory.createTitledBorder(BorderFactory.createLineBorder(Color.black), "");
		this.setBorder(title);
		this.emailApplicationView = emailApplicationView;
	}
	
	/**
	 * initialize
	 */
	public void initialize()
	{
        this.mailbox = new EmailFolderNode(ResourceProvider.MAILBOX);    
        this.etree = new EMailFolderHierarchyTree(emailApplicationView,mailbox);
        this.add(new JScrollPane(this.etree));
	}
	
	/**
	 * load persistence folders
	 */
	public void loadPersistenceFolders()
    {
        this.etree.loadPersistenceFolders();
    }
	
	
	/**
	 * get email application view reference
	 * @return email application view reference
	 */
	public EmailApplicationView getEmailApplicationView()
    {
        return this.emailApplicationView;
    }
	
	/**
	 * get selected tree node path
	 * @return selected tree node path
	 */
	public String getSelectedTreeNodePath()
	{
	    EmailFolderNodeImp selectedNode = (EmailFolderNodeImp)this.etree.getLastSelectedPathComponent();
	    return selectedNode.getPersistenceFilePath();
	}
	
	/**
	 * get tree reference
	 * @return the email folder hierarchy tree reference
	 */
	public EMailFolderHierarchyTree getTree()
	{
	    return etree;
	}
}
